The OutputWidget

The output widget can be used to display rich output. IHaskell.Display provides functions to create such rich displays from raw data.


In [1]:
{-# LANGUAGE OverloadedStrings #-}
import IHaskell.Display.Widgets
import IHaskell.Display
:t plain
:t html
:t jpg
:t svg
:t latex
:t javascript
:t many


plain :: String -> DisplayData
html :: String -> DisplayData
jpg :: Width -> Height -> Base64 -> DisplayData
svg :: String -> DisplayData
latex :: String -> DisplayData
javascript :: String -> DisplayData
many :: [Display] -> Display

The Output widget is meant to be used through the functions:

  • appendOutput: Append more output to the widget.
  • clearOutput: Clear the output widget ASAP.
  • clearOutput_: Clear the output widget on next use of appendOutput.
  • replaceOutput: Clear then append.

In [2]:
import Text.Printf
o <- mkOutputWidget -- Make output widget
setField o Width 500
o -- Display output widget

fmt = "<font color=\"%s\"><marquee direction=\"%s\" style=\"background:%s\">%s</marquee></font>"
add fg bg dir txt = appendOutput o $ html $ printf fmt fg dir bg txt

add "WHITE" "RED" "left" "The <b>OUTPUT</b> Widget"
add "WHITE" "BLUE" "right" "Is really <b>SIMPLE</b>"
add "WHITE" "GREEN" "left" "Use it as an <b>UPDATABLE</b> display</b>"

Currently, the output widget doesn't support displaying other widgets inside it. It does so in IPython, but not in IHaskell.